//
//  TravelNotesTableViewCell.m
//  ITrip
//
//  Created by dlios on 15-5-21.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TravelNotesTableViewCell.h"
#import "TravelNotesParser.h"
#import <AFNetworking.h>
#import "UIImageView+AFNetworking.h"
@implementation TravelNotesTableViewCell

- (void)dealloc
{
    [_front_cover_photo_url release];
    [_image release];
    [_name release];
    [_start_date release];
    [_travelNotesModel release];
    [super dealloc];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.contentView.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 10);
    self.front_cover_photo_url.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    self.front_cover_photo_url.layer.cornerRadius = 4;
    self.front_cover_photo_url.layer.masksToBounds = YES;
    self.name.frame = CGRectMake(20, 20, self.contentView.frame.size.width - 40, 40);
    self.name.numberOfLines = 2;
    self.name.textColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1];
    self.name.font = [UIFont systemFontOfSize:25];
    self.name.font = [UIFont boldSystemFontOfSize:23];
    [self.name sizeToFit];
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:25] forKey:NSFontAttributeName];
    CGRect frame = [self.name.text boundingRectWithSize:CGSizeMake(self.contentView.frame.size.width - 20, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.start_date.frame = CGRectMake(20, 10 + frame.size.height, self.contentView.frame.size.width - 40, 40);
    self.start_date.font = [UIFont systemFontOfSize:15];
    self.start_date.font = [UIFont boldSystemFontOfSize:18];
    self.start_date.textColor = [UIColor whiteColor];
    self.image.frame = CGRectMake(20, self.contentView.frame.size.height - 50, 30, 30);
    self.image.layer.cornerRadius = 15;
    self.image.layer.masksToBounds = YES;
    self.image.layer.borderWidth = 1.5;
    self.image.layer.borderColor = [UIColor whiteColor].CGColor;
}


- (void)setTravelNotesModel:(TravelNotesModel *)travelNotesModel
{
    if (travelNotesModel.name != nil && ![travelNotesModel.name isEqual:[NSNull null]]) {
        self.name.text = travelNotesModel.name;
    }
    if (travelNotesModel.start_date != nil && ![travelNotesModel.name isEqual:[NSNull null]]) {
        self.start_date.text = [[travelNotesModel.start_date stringByAppendingFormat:@"/%ld天", travelNotesModel.days] stringByAppendingFormat:@",%ld图", travelNotesModel.photos_count];
    }
    if (travelNotesModel.front_cover_photo_url != nil && ![travelNotesModel.front_cover_photo_url isEqual:[NSNull null]]) {
        self.front_cover_photo_url.contentMode = UIViewContentModeRedraw;
        [self.front_cover_photo_url setImageWithURL:[NSURL URLWithString: travelNotesModel.front_cover_photo_url] placeholderImage:[UIImage imageNamed:@"defaultPic_Down"]];
        [self.image setImageWithURL:[NSURL URLWithString:travelNotesModel.image] placeholderImage:nil];
    }
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)createCell
{
    self.front_cover_photo_url = [[UIImageView alloc] init];
    [self.contentView addSubview:self.front_cover_photo_url];
    self.name = [[UILabel alloc] init];
    [self.front_cover_photo_url addSubview:self.name];
    self.start_date = [[UILabel alloc] init];
    [self.front_cover_photo_url addSubview:self.start_date];
    self.image = [[UIImageView alloc] init];
    [self.front_cover_photo_url addSubview:self.image];
    
    [self.front_cover_photo_url release];
    [self.name release];
    [self.image release];
    [self.start_date release];
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
